home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
batchut
/
rap101.zip
/
DEMO.RAP
< prev
next >
Wrap
Text File
|
1988-10-26
|
6KB
|
314 lines
; DEMO.RAP -- Interactive demo of some common.rap functions
;
; Kirk Parker, 19-Nov-87
;
.define .TESTDECL declare $my_prompt,$my_def,#my_min,#my_max,#my_oblig,#first_time
.define .STRING 1
.define .NUMERIC 2
.define .FILE 3
.include common.rap
; ----------------------------------------------------------
proc main
declare #i
$test[0]=YES
$test[1]=NO
$test[2]=GET_STR
$test[3]=GET_NUM
$test[4]=GET_CODE
$test[5]=GET_FILESPEC
#end_test = 6
ch
t:
t: Demonstration of RAP SUBROUTINE LIBRARY
t:
t:
loop while (#i < #end_test)
if (*yes("Test subroutine $test[#i]","",""))
xi test_$test[#i]
endif
#i = #i + 1
endloop
endproc
; ----------------------------------------------------------
proc test_get_str()
.TESTDECL
declare $my_str
#first_time = 1
loop
get_params(.STRING,#first_time,"get_str")
#first_time = 0
$my_str=*get_str($my_prompt,$my_def,"",#my_min,#my_max,#my_oblig)
t:$skip You entered <$my_str>
until (*no("Repeat this test","",""))
endproc
; ----------------------------------------------------------
proc test_get_code()
.TESTDECL
declare $my_code
#first_time = 1
loop
get_params(.STRING,#first_time,"get_code")
#first_time = 0
$my_code=*get_code($my_prompt,$my_def,"",#my_min,#my_max)
t:$skip You entered <$my_code>
until (*no("Repeat this test","",""))
endproc
; ----------------------------------------------------------
proc showyes(#n)
t:$skip Your answer was \
if (#n == 0)
t:NO. \
else
t:YES. \
endif
t:(function returned \
endproc
; ----------------------------------------------------------
proc showno(#n)
showyes(not #n)
endproc
; ----------------------------------------------------------
proc test_get_num()
.TESTDECL
declare #my_num
#first_time = 1
loop
get_params(.NUMERIC,#first_time,"get_num")
#first_time = 0
#my_num = *get_num($my_prompt,$my_def,"",#my_min,#my_max)
t:$skip you entered <#my_num>
until (*no("repeat this test","",""))
endproc
; ----------------------------------------------------------
proc get_params(#type,#first_time,$name)
if (not #first_time)
if (*no("Revise parameters","",""))
return
endif
endif
signon($name)
set_params(#type,#first_time)
endproc
; ----------------------------------------------------------
proc set_params(#type,#first_time)
declare $min_prompt,$max_prompt,#min_lwr,#min_upr,#max_lwr,#max_upr, $is_oblig
$my_prompt=*get_str(" Enter a prompt string:",$my_prompt,"",0,40,0)
if (#type == .FILE)
$my_path=*get_str(" Default path:",$my_path,"",0,40,0)
$my_file=*get_str(" Default file:",$my_file,"",0,8,0)
$my_ext=*get_str(" Default ext:",$my_ext,"",0,4,0)
else ; string or numeric
if (#type == .STRING)
if ($my_def == "")
$my_def=*get_str(" Enter a default:",$my_def,"",0,40,0)
else if (*yes(" Default is <$my_def> - delete it","",""))
$my_def=
endif
if (#first_time)
#my_max = 40
else
if (#my_oblig)
$is_oblig=y
else
$is_oblig=n
endif
endif
if ($my_def == "")
#my_oblig = *yes(" Is the input obligatory",$is_oblig,"")
else
#my_oblig = 0
endif
$min_prompt=Minimum length:
$max_prompt=Maximum length:
if (#my_oblig)
#min_lwr = 1
#my_min = 1
else
#min_lwr = 0
#my_min = 0
endif
#min_upr = 39
#max_upr = 40
else ; it's numeric
$min_prompt=Minimum value:
$max_prompt=Maximum value:
#min_lwr = .MININT
#min_upr = .MAXINT
#max_upr = .MAXINT
if (#first_time)
#my_min = .MININT
#my_max = .MAXINT
endif
loop
$my_def=*get_str(" Default:",$my_def,"",0,5,0)
exit if (($my_def == "") or (*isnumber($my_def)))
error(" The default must be a number","")
endloop
endif
#my_min = *get_num(" $min_prompt","#my_min","",#min_lwr,#min_upr)
if ((#type == .STRING) and (#my_min < 1))
#max_lwr = 1
else
#max_lwr = #my_min
endif
#my_max = *between(#my_max,#max_lwr,#max_upr)
#my_max = *get_num(" $max_prompt","#my_max","",#max_lwr,#max_upr)
endif
endproc
; ----------------------------------------------------------
proc test_yes()
declare #my_yes
signon("yes")
loop
#my_yes = *yes("Answer yes or no (default not allowed)","","")
t:*showyes(#my_yes)#my_yes)
#my_yes = *yes("Answer yes or no","y","")
t:*showyes(#my_yes)#my_yes)
#my_yes = *yes("Answer yes or no","n","")
t:*showyes(#my_yes)#my_yes)
t:
until (*no("Repeat this test","",""))
endproc
; ----------------------------------------------------------
proc test_no()
declare #my_yes
signon("no")
loop
#my_yes = *no("Answer yes or no (default not allowed)","","")
t:*showno(#my_yes)#my_yes)
#my_yes = *no("Answer yes or no","y","")
t:*showno(#my_yes)#my_yes)
#my_yes = *no("Answer yes or no","n","")
t:*showno(#my_yes)#my_yes)
t:
until (*no("Repeat this test","",""))
endproc
; ----------------------------------------------------------
proc signon($name)
kbflush()
ch
t:Test of \*$name()
t:
endproc
; ----------------------------------------------------------
numfunc between(#arg,#min,#max) ; return copy of #arg forced between min & max
if (#arg < #min)
return (#min)
else if (#arg > #max)
return (#max)
else
return (#arg)
endif
endfunc
; ----------------------------------------------------------
proc test_get_filespec()
.TESTDECL
declare $my_path,$my_file, $my_ext, $my_filespec
#first_time = 1
loop
get_params(.FILE,#first_time,"get_filespec")
#first_time = 0
$my_filespec=*get_filespec($my_prompt,$my_path,$my_file,$my_ext,"")
#sstep=0
t:$skip You entered <$my_filespec>
until (*no("Repeat this test","",""))
endproc